package com.fengze.business.service.impl;

import com.fengze.business.domain.ContractInfo;
import com.fengze.business.domain.InquiryRecord;
import com.fengze.business.domain.ProjectInfo;
import com.fengze.business.mapper.*;
import com.fengze.business.service.DashBoardService;
import com.fengze.business.vo.ContractInfoVO;
import com.fengze.business.vo.InquiryRecordVO;
import com.fengze.business.vo.ProjectInfoVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DashBoardServiceImpl implements DashBoardService {

    @Resource
    private InquiryRecordMapper inquiryRecordMapper;


    @Resource
    private ProjectInfoMapper projectInfoMapper;

    @Resource
    private ContractInfoMapper contractInfoMapper;

    @Resource
    private PerformancePlanMapper performancePlanMapper;


    @Resource
    private EarlyStageProjectMapper earlyStageProjectMapper;

    /**
     * 查询统计数量接口
     * @return
     */
    @Override
    public Map<String, Object> queryStaticsNum() {

        // 询价数量
        int  inquiryTotal = inquiryRecordMapper.total();
        // 项目数量
        int projectTotal = projectInfoMapper.total();

        // 合同数量
        int contractTotal = contractInfoMapper.total();

        // 有风险的合同数量
        int danagerContractTotal = performancePlanMapper.danagerTotal();

        // 有风险的项目数量
        int danagerProjectTotal = projectInfoMapper.danagerTotal();

        Map<String,Object> result = new HashMap<>(3);
        result.put("inquiryTotal",inquiryTotal);
        result.put("projectTotal",projectTotal);
        result.put("contractTotal",contractTotal);
        result.put("danagerContractTotal",danagerContractTotal);
        result.put("danagerProjectTotal", danagerProjectTotal);
        return result;
    }

    @Override
    public List<InquiryRecordVO> query(InquiryRecord record) {
        return inquiryRecordMapper.selectVOList(record);
    }

    @Override
    public List<ProjectInfoVO> queryProjectList(ProjectInfo projectInfo) {
        List<ProjectInfoVO> list = projectInfoMapper.queryList(projectInfo);
//        // 设置状态
//        for (ProjectInfoVO projectInfoVO : list) {
//
//        }
        return list;
    }

    @Override
    public List<ContractInfoVO> queryContractList(ContractInfo contractInfo) {
        List<ContractInfoVO> list = contractInfoMapper.queryList(contractInfo);
        // 设置状态
        for (ContractInfoVO contractInfoVO : list) {
            // 查询违约信息数量
            int count = performancePlanMapper.breachTotal(contractInfoVO.getId());

            if(count > 0){
                // 已违约
                contractInfoVO.setStatus(1);
            }else{
                // 正常
                contractInfoVO.setStatus(0);
            }
        }
        return list;
    }

    @Override
    public List<InquiryRecordVO> queryInquiryList(InquiryRecord record) {
        return earlyStageProjectMapper.selectList(record.getProjectName());
    }
}
